<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Parsing of custom resources: GTK+ 3 Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="GTK+ 3 Reference Manual">
<link rel="up" href="gtk-migrating-GtkStyleContext.html" title="Theming changes">
<link rel="prev" href="gtk-migrating-GtkStyleContext-checklist.html" title="A checklist for widgets">
<link rel="next" href="gtk-migrating-GtkStyleContext-bonus-points.html" title="Bonus points">
<meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="gtk-migrating-GtkStyleContext.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="gtk-migrating-GtkStyleContext-checklist.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="gtk-migrating-GtkStyleContext-bonus-points.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="gtk-migrating-GtkStyleContext-parsing"></a>Parsing of custom resources</h2></div></div></div>
<p>
      As a consequence of the RC format going away, calling <a class="link" href="gtk3-Resource-Files.html#gtk-rc-parse" title="gtk_rc_parse ()"><code class="function">gtk_rc_parse()</code></a> or
      <a class="link" href="gtk3-Resource-Files.html#gtk-rc-parse-string" title="gtk_rc_parse_string ()"><code class="function">gtk_rc_parse_string()</code></a> won't have any effect on a widgets appearance.
      The way to replace these calls is using a custom <a class="link" href="GtkStyleProvider.html" title="GtkStyleProvider"><span class="type">GtkStyleProvider</span></a>,
      either for an individual widget through <a class="link" href="GtkStyleContext.html#gtk-style-context-add-provider" title="gtk_style_context_add_provider ()"><code class="function">gtk_style_context_add_provider()</code></a>
      or for all widgets on a screen through <a class="link" href="GtkStyleContext.html#gtk-style-context-add-provider-for-screen" title="gtk_style_context_add_provider_for_screen ()"><code class="function">gtk_style_context_add_provider_for_screen()</code></a>.
      Typically, the provider will be a <a class="link" href="GtkCssProvider.html" title="GtkCssProvider"><span class="type">GtkCssProvider</span></a>, which parse CSS
      information from a file or from a string.
    </p>
<div class="example">
<a name="id-1.6.4.8.3"></a><p class="title"><b>Example 49. Using a custom GtkStyleProvider</b></p>
<div class="example-contents">
  <table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
    <tbody>
      <tr>
        <td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13</pre></td>
        <td class="listing_code"><pre class="programlisting"><span class="n">GtkStyleContext</span> <span class="o">*</span><span class="n">context</span><span class="p">;</span>
<span class="n">GtkCssProvider</span> <span class="o">*</span><span class="n">provider</span><span class="p">;</span>

<span class="n">context</span> <span class="o">=</span> <span class="n">gtk_widget_get_style_context</span> <span class="p">(</span><span class="n">widget</span><span class="p">);</span>
<span class="n">provider</span> <span class="o">=</span> <span class="n">gtk_css_provider_new</span> <span class="p">();</span>
<span class="n">gtk_css_provider_load_from_data</span> <span class="p">(</span><span class="n">GTK_CSS_PROVIDER</span> <span class="p">(</span><span class="n">provider</span><span class="p">),</span>
                                 <span class="s">&quot;.frame1 {</span><span class="se">\n</span><span class="s">&quot;</span>
                                 <span class="s">&quot;   border-image: url(&#39;gradient1.png&#39;) 10 10 10 10 stretch;</span><span class="se">\n</span><span class="s">&quot;</span>
                                 <span class="s">&quot;}</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="mi">-1</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="n">gtk_style_context_add_provider</span> <span class="p">(</span><span class="n">context</span><span class="p">,</span>
                                <span class="n">GTK_STYLE_PROVIDER</span> <span class="p">(</span><span class="n">provider</span><span class="p">),</span>
                                <span class="n">GTK_STYLE_PROVIDER_PRIORITY_APPLICATION</span><span class="p">);</span>
<span class="n">g_object_unref</span> <span class="p">(</span><span class="n">provider</span><span class="p">);</span></pre></td>
      </tr>
    </tbody>
  </table>
</div>

</div>
<br class="example-break"><p>
      Notice that you can also get style information from custom resources
      by implementing the <a class="link" href="GtkStyleProvider.html" title="GtkStyleProvider"><span class="type">GtkStyleProvider</span></a> interface yourself. This is
      an advanced feature that should be rarely used.
    </p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.1</div>
</body>
</html>